package com.yzd.learnjava.concurrency;

import com.yzd.learnjava.util.Print;

public class SyncObject {
	public static void main(String[] args) {
		final DualSynch ds = new DualSynch();
		new Thread() {
			public void run() {
				ds.f();
			}
		}.start();
		ds.g();
	}
}

class DualSynch{
	private Object  syncObject = new Object();
	public synchronized void f() {
		for(int i = 0 ; i < 250; i++) {
			Print.print("f()");
			Thread.yield();
		}
	}
	
	public void g() {
		synchronized(syncObject) {
			for(int i = 0 ; i < 250; i++) {
				Print.print("g()");
				Thread.yield();
			}
		}
	}
}
